package com.peanut.baby.mvp.task;

import android.app.Activity;

import com.peanut.baby.InitManager;
import com.peanut.baby.http.BaseObserver;
import com.peanut.baby.http.BaseScheduler;
import com.peanut.baby.http.RetrofitClient;
import com.peanut.baby.model.ShareType;
import com.peanut.baby.model.VarPoint;
import com.tencent.mars.xlog.Log;

import io.reactivex.Observable;

/**
 * Created by anonymouslystudio on 2017/8/29.
 */

public class TaskPresenter implements TaskContract.Presenter{
    private static final String TAG = TaskPresenter.class.getSimpleName();
    private TaskContract.View view;
    Activity activity;
    public TaskPresenter(TaskContract.View view,Activity activity) {
        this.view = view;
        this.activity  =activity;
    }

    @Override
    public void sharePoint() {
        Observable obs = RetrofitClient.getInstance().sharePoint(InitManager.getInstance().getUserId(),
                ShareType.TYPE_SHARE_APP+"","");
        obs.compose(BaseScheduler.<VarPoint>compose())
                .subscribe(new BaseObserver<VarPoint>() {
            @Override
            protected void onHandleSuccess(VarPoint o) {
                InitManager.getInstance().getUser().userPoint = o.totalPoint;
                InitManager.getInstance().updateLocalUser();
                view.onSharePoint("花生壳加"+o.variedPoint+",总花生壳"+o.totalPoint);
            }

            @Override
            protected void onHandleError(String code,String msg) {
                Log.w(TAG,"sharePoint failed "+msg);
//                view.onSharePointSuccess(msg);
            }
        });
    }
}
